<?php

/**
 * This is the model class for table "partner_invoice".
 *
 * The followings are the available columns in table 'partner_invoice':
	 * @property integer $partner_invoice_id
	 * @property string $issued_user
	 * @property integer $user_id
	 * @property double $sumamount
	 * @property double $undisbursed_amount
	 * @property double $issued_amount
	 * @property string $create_time
	 * @property string $update_time
 */
class PartnerInvoice extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return PartnerInvoice the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'partner_invoice';
	}
	public function primaryKey()
	{
		return 'partner_invoice_id';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('user_id', 'numerical', 'integerOnly'=>true),
			array('sumamount, undisbursed_amount, issued_amount', 'numerical'),
			array('issued_user', 'length', 'max'=>100),
			array('create_time, update_time', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('partner_invoice_id, issued_user, user_id, sumamount, undisbursed_amount, issued_amount, create_time, update_time', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'partner_invoice_id' =>Yii::t("PartnerInvoice","Partner Invoice ID"),
			'issued_user' =>Yii::t("PartnerInvoice","Issued User"),
			'user_id' =>Yii::t("PartnerInvoice","User ID"),
			'sumamount' =>Yii::t("PartnerInvoice","Sumamount"),
			'undisbursed_amount' =>Yii::t("PartnerInvoice","Undisbursed Amount"),
			'issued_amount' =>Yii::t("PartnerInvoice","Issued Amount"),
			'create_time' =>Yii::t("PartnerInvoice","Create Time"),
			'update_time' =>Yii::t("PartnerInvoice","Update Time"),
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('partner_invoice_id',$this->partner_invoice_id);
		$criteria->compare('issued_user',$this->issued_user,true);
		$criteria->compare('user_id',$this->user_id);
		$criteria->compare('sumamount',$this->sumamount);
		$criteria->compare('undisbursed_amount',$this->undisbursed_amount);
		$criteria->compare('issued_amount',$this->issued_amount);
		$criteria->compare('create_time',$this->create_time,true);
		$criteria->compare('update_time',$this->update_time,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
			'sort'=>array(  
           		 'defaultOrder'=>'partner_invoice_id DESC',  
       		 ),  
       		'pagination'=>array(  
           		 'pageSize'=>20  
       		 ),  
		));
	}
	
	
	
	//获取合作商名字
	
	public function getPartnerName($user_id)
	
	{
	    $user=User::model()->findByPk($user_id);
	     
	    return $user->user_name;
	
	}
	
	
	//获取合作商搜索的下拉列表
	
	public function getPartner()
	
	{
	    $sql='select * from partner_invoice a,zy_user b where a.user_id=b.user_id';
	
	    $rs=yii::app()->db->createCommand($sql)->queryAll();
	
	    //$model=PartnerInvoice::model()->findAll();
	     
	    return CHtml::listData($rs,'user_id','user_name');
	}
}